home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / tls / tls011.1.Z / tls011.1 / tmp / perms / prep.mmdfsls1 < prev   
Encoding:
Text File  |  1992-02-11  |  10.5 KB  |  450 lines

  1. :
  2. #BEGIN_CM_SCRIPTLIB
  3. #
  4. # Standard CM script function library
  5. # baselib v1.2
  6. #
  7.  
  8. PATH=/bin:/usr/bin:/etc:.
  9. LANG=english_us.ascii    # Used when scripts are internationalized.
  10. export PATH LANG
  11.  
  12. TMPFILE=/tmp/tmp$$    # Define a temporary file for use if necessary.
  13. TMPFILE1=/tmp/tmp1$$    # Define a temporary file for use if necessary.
  14. TMPFILE2=/tmp/tmp2$$    # Define a temporary file for use if necessary.
  15.  
  16. # Define return values.
  17. : ${OK=0} ${FAIL=1} ${STOP=10}
  18.  
  19. #
  20. # Print an error message.
  21. #
  22. error() {
  23.     echo "\nError: $*" >&2
  24.     return 0
  25. }
  26.  
  27. #
  28. # Prompt for yes or no answer - returns non-zero for no.
  29. #
  30. getyn() {
  31.     while    echo "$* (y/n) \c"
  32.     do    read yn rest
  33.         case $yn in
  34.         [yY])    return $OK             ;;
  35.         [nN])    return $FAIL            ;;
  36.         *)    error "Please answer y or n"     ;;
  37.         esac
  38.     done
  39.     return 0
  40. }
  41.  
  42. #
  43. # prdrel: given a prd value, return the release number of that
  44. # product in the variable PRDREL.
  45. # Return 0 if release is sucessfully gotten, return 1 if
  46. # the release cannot be gotten.
  47. #
  48. PRDREL1="Checking for requested release information..."
  49. prdrel() {
  50.  
  51.     _pd="$1"
  52.     [ -n "${_pd}" ] || return 1
  53.     PRDREL=""
  54.     # tmp file name
  55.     _prtmp=/tmp/pr$$
  56.  
  57.     if [ -f /etc/perms/${_pd} ] 
  58.     then
  59.     PRDREL=`sed -n '/^#rel=/s///p'  /etc/perms/${_pd}` || return 1
  60.     else
  61.     # There is no permlist with <prd> as its name, so search for 
  62.     # permlists looking for appropriate #prd=... entry.
  63.     # Ignore update p'lists here.  This code handles products
  64.     # with several p'lists, primarily the OS and DS.
  65.     # Pipe thru sort -r to get the highest rel first, and
  66.     # put results into temporary file. (Ideally would pipe
  67.     # them into 'read PRDREL', but this doesn't work under sh.)
  68.     echo "$PRDREL1"
  69.     : >${_prtmp}        # Clear temporary file.
  70.     for _ff in /etc/perms/*
  71.     do
  72.         [ -f ${_ff} ] || continue    # Process regular files only
  73.         _p=
  74.         _u=
  75.         _r=
  76.         eval `sed -n  '/^#rel=/s//_r=/p
  77.                /^#upd=/s//_u=/p
  78.                /^#prd=/s//_p=/p
  79.                /^[A-Z]/q
  80.                ' ${_ff} `  2>/dev/null
  81.         # If permlist prd matches wanted one, and it is not an upd,
  82.         # use rel= value.
  83.         [ -z "${_u}" -a "${_p}" = "${_pd}" ] && {
  84.         echo ${_r}
  85.         }
  86.     done  | sort -r > ${_prtmp}  2>/dev/null
  87.  
  88.     [ -s ${_prtmp} ] && PRDREL=`sed 1q  ${_prtmp}`
  89.     rm -f ${_prtmp}  2>/dev/null        # Clean up tmp file.
  90.     fi
  91.  
  92.     # Check if PRDREL has been set, return 1 if not.
  93.     [ -z "$PRDREL" ] && return 1
  94.     return 0
  95. }
  96.  
  97. #
  98. #query the user for a responce.
  99. #a simpler system than prompt, use prompt for
  100. #more sophisticated uses.
  101. #q or Q returns fail, anything else return ok.
  102. #ARGS: <string>, string to print when asking for a responce
  103. #$OK means expression has been resolved or answer is given 
  104. #$FAIL means quit has been selected
  105. #
  106. respond() {
  107.     while    echo "\n${*}\nRespond or enter q to quit: \c" 
  108.     do    read answer
  109.         case $answer in
  110.         Q|q)    return $FAIL                    ;;
  111.         "")    # on a return key return $OK
  112.             answer="RETURNKEY"
  113.             return $OK            ;;
  114.         *)    # on anything else return $OK
  115.             return $OK                    ;;
  116.         esac
  117.     done
  118.     return $OK
  119. }
  120.  
  121. #
  122. # SHOULD BE USED WITH EVERY INSTALLATION SCRIPT
  123. #
  124. # Set the variable $prdperm to  /etc/perms/$PRDVALUE or ./tmp/perms/$PRDVALUE
  125. # If the permlist is found, the values for set, prd, ver, typ, rel,
  126. # and upd are set from the permlist.
  127. # Also determine the OS type, xenix or unix, and set systype accordingly.
  128. #
  129. # sets following information in exported variables
  130. # OSREL: x.x.xy    OSTYPE: unix|xenix    OSBUS: isa|mc
  131. # OSPRD: <prd value>    OSMCH: <os machine type>
  132. # echo "OS Release: $OSREL    OS Type: $OSTYPE    OS Bus: $OSBUS"
  133. # echo "OS PRD Value: $OSPRD    OS Machine Type: $OSMCH"
  134. #
  135. SETVARS1="Permlist not found"
  136. SETVARS2="Failed to set values from"
  137. SETVARS3="Incorrect prd value in"
  138.  
  139. # Variables set by setvars.
  140. prdperm=
  141. fixperm=fixperm
  142. brand=brand
  143. set=
  144. prd=
  145. typ=
  146. rel=
  147. ser=
  148. upd=
  149. systype=unknown
  150.  
  151. setvars() {
  152.  
  153. # Locate fixperm, brand, and the permlist.
  154.     for _i in /etc ./tmp
  155.     do
  156.         [ -f "$_i/fixperm" ] && fixperm=$_i/fixperm
  157.         [ -f "$_i/brand" ] && brand=$_i/brand
  158.         [ -f "$_i/perms/$PRDVALUE" ] && prdperm=$_i/perms/$PRDVALUE
  159.     done
  160.  
  161.     [ "$prdperm" ] || {
  162.         echo "Warning: $PRDVALUE $SETVARS1" >&2
  163.         return 1
  164.     }
  165.  
  166. # Get the operating system type:
  167.     case `uname -r` in
  168.         2.*)    systype=xenix
  169.             ;;
  170.         3.*)    systype=unix
  171.             ;;
  172.         *)    systype=unknown
  173.             ;;
  174.     esac
  175.  
  176. #
  177. # OS variables setting
  178. # OSREL: x.x.xy        OSTYPE: unix|xenix    OSBUS: isa|mc
  179. # OSPRD: <prdvalue>    OSMCH: os mch type
  180. #
  181.     OSTYPE=$systype
  182.     case "$OSTYPE" in
  183.         unix)
  184.         eval `sed -n '/^#prd=/s/#//p
  185.             /^#typ=/s/#//p
  186.             /^#rel=/s/#//p' /etc/perms/rtsmd` > /dev/null 2>&1
  187.             OSREL=$rel
  188.             OSPRD=$prd
  189.             OSMCH=$typ
  190.             if [ -r /dev/mcapos ]
  191.             then
  192.                 if grep mcapos /etc/perms/rtsmd > /dev/null 2>&1
  193.                 then
  194.                     OSBUS=mc
  195.                 fi
  196.             else
  197.                 OSBUS=isa
  198.             fi
  199.         ;;
  200.         xenix)
  201.         eval `sed -n '/^#prd=/s/#//p
  202.             /^#typ=/s/#//p
  203.             /^#rel=/s/#//p' /etc/perms/inst` > /dev/null 2>&1
  204.             OSREL=$rel
  205.             OSPRD=$prd
  206.             OSMCH=$typ
  207.             var=`expr $OSMCH : '.*\(..\)$'`
  208.             if [ "$var" = "MC" -o "$var" = "PS" ]
  209.             then
  210.                 OSBUS=mc
  211.             else
  212.                 OSBUS=isa
  213.             fi
  214.         ;;
  215.         *)
  216.             OSREL=unknown
  217.             OSTYPE=unknown
  218.             OSBUS=unknown
  219.             OSPRD=unknown
  220.             OSMCH=unknown
  221.         ;;
  222.     esac
  223.  
  224.     export OSREL OSTYPE OSBUS OSPRD OSMCH
  225.     # Clear these vars before they are used below.
  226.     prd=
  227.     rel=
  228.     typ=
  229.     
  230. # Extract product info from the permlist.
  231.     eval `sed -n '/^#set=/s/#//p
  232.         /^#prd=/s/#//p
  233.         /^#typ=/s/#//p
  234.         /^#rel=/s/#//p
  235.         /^#ser=/s/#//p
  236.         /^#upd=/s/#//p' $prdperm` || echo "\n$SETVARS2 $prdperm" >&2
  237.  
  238. # Check the prd value read from the permlist for correctness.
  239.  
  240.     case "$prd" in
  241.         "$PRDVALUE")    return 0
  242.                 ;;
  243.               *)    echo "\n$SETVARS3 $prdperm"  >&2
  244.                 return 1
  245.                 ;;
  246.     esac
  247.  
  248.     return 0
  249. }
  250.  
  251. #
  252. # tarcomp:  Determines whether the system 'tar' is capable of decompressing.
  253. # files automatically.  The command tar is used unless another is
  254. # specified in the variable TARPROG.
  255. # Returns 'true' (0) if the tar program can decompress, 'fail' if it cannot.
  256. #
  257. tarcomp() {
  258.  
  259.     # Set TARPROG to default of tar if not set.
  260.     : ${TARPROG:=tar}
  261.     tctmp=/tmp/tc$$        # Name for tmp files.
  262.  
  263.     # Eminently compressible data to go into file. (60 'a's)
  264.     _ptrn="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
  265.  
  266.     echo ${_ptrn} | compress -F > $tctmp.A    # Compress data.
  267.  
  268.     # Tar to an archive file, with headers set to indicate compression.
  269.     ${TARPROG} Cf $tctmp.T  $tctmp.A  2>/dev/null || {
  270.     rm -rf $tctmp.* 
  271.     return 1
  272.     }
  273.  
  274.     # Now restore original file from archive - it should automagically
  275.     # be decompressed.
  276.     rm -f $tctmp.A
  277.     ${TARPROG} xf $tctmp.T  2>/dev/null  || {
  278.     rm -rf $tctmp.*
  279.     return 1
  280.     }
  281.  
  282.     # Compare it to the original data.
  283.     echo ${_ptrn} | cmp -s - $tctmp.A  2>/dev/null || {
  284.     rm -rf $tctmp.*
  285.     return 1
  286.     }
  287.  
  288.     # If we got here, the two compared equal, which
  289.     # implies that the compress/decompress cycle worked.
  290.     rm -rf $tctmp.*
  291.     return 0
  292. }
  293.  
  294. #
  295. # Standard CM script function library
  296. # configlib V1.0
  297. # Contains: baselib, specificlib
  298. #
  299.  
  300. #
  301. # Standard CM script function library
  302. # specificlib v1.4
  303. # contains: baselib
  304. #
  305.  
  306. #
  307. # backs up all files based on permslist that is on the
  308. # path given as arg1. files will be backed up in the STANDARD location
  309. # ARG1: PRDVALUE of product so files can be placed in the standard location
  310. # Usage:    allbackup <prdvalue>
  311. #
  312. ALLBACKUP1="Creating list of files to be overwritten..."
  313. ALLBACKUP2="
  314. You now have the opportunity to backup
  315. all files that may be overwritten during this
  316. product's installation.
  317. You can restore these files if required.
  318. You will need to verify that you have
  319. enough disk space available if you
  320. choose to backup. This product puts its
  321. backup files in the following location: "
  322.  
  323.  
  324. allbackup() {
  325.     PERMARG=$1
  326.  
  327.     cd /
  328.     rm -f $TMPFILE
  329.     echo "$ALLBACKUP1"
  330.     # -l lists both files and directories in the permlist.
  331.     fixperm -u PERM -l /tmp/perms/$PERMARG > $TMPFILE
  332.     if [ -s "$TMPFILE" ]
  333.     then
  334.         echo "$ALLBACKUP2"
  335.         echo "/usr/lib/custom/${PERMARG}/backup\n"
  336.         onlinebackup $PERMARG $TMPFILE || return 1     
  337.         rm -f $TMPFILE
  338.     fi
  339.     return $OK
  340. }
  341.  
  342. #
  343. # onlinebackup
  344. #
  345. # This function takes as arguments the prd of the product being installed
  346. # and the name of a file listing files to be backed-up.  The list of 
  347. # files is checked, and those files that exist on the system will
  348. # be saved under the backup directory for the product
  349. # ARG1: PRDVALUE of product so files can be placed in the standard location
  350. #    ( /usr/lib/custom/$PRDVALUE/backup )
  351. # ARG2: Name of a file listing files that are to be backed-up (one name
  352. #    per line in the file; these filenames should be pathnames relative 
  353. #    to /, not absolute pathnames).  This list may include
  354. #    directory names; if directories are included, they will be 
  355. #    created under the backup directory with their own mode/uid/gid.
  356. #    Directories not listed will be created as necessary under the 
  357. #    backup directory, using the current default mode/uid/gid.
  358. # Usage:    onlinebackup <prdvalue> <file list path>
  359. #
  360. #ONLINE0="Creating backup list..."
  361. ONLINE1="Do you want to see the file list ?"
  362. ONLINE2=" <Press Return to Continue>"
  363. ONLINE3="
  364. It is estimated that you will need the
  365. following amount of space to backup
  366. the selected files online.
  367. Computing estimate
  368. in 512 byte blocks...
  369. "
  370. ONLINE4="Do you want to backup these files ?"
  371. ONLINE5="There are no existing files that require backing up."
  372. onlinebackup() {
  373.     PRDARG=$1
  374.     LISTARG=$2
  375.     # Check that both are non-null
  376.     : ${PRDARG:?}  ${LISTARG:?}
  377.  
  378.     cd /
  379.     rm -rf $TMPFILE2
  380.     echo " "
  381. #    echo "$ONLINE0"
  382.     cat $LISTARG | while read file
  383.     do
  384.         [ -r "$file" ] && echo $file >> $TMPFILE2
  385.     done
  386.     if [ -s "$TMPFILE2" ]
  387.     then
  388.         getyn "$ONLINE1" && pg -p "$ONLINE2" $TMPFILE2
  389.         echo "$ONLINE3"
  390.         cat $TMPFILE2 | cpio -ocB | dd of=/dev/null bs=10b > /dev/null 2>&1 
  391.         echo " "
  392.         getyn "$ONLINE4" && {
  393.             mkdir /usr/lib/custom/${PRDARG} > /dev/null 2>&1
  394.             mkdir /usr/lib/custom/${PRDARG}/backup > /dev/null 2>&1
  395.             cat $TMPFILE2 | cpio -pdmuv /usr/lib/custom/${PRDVALUE}/backup || return 1      
  396.         }
  397.         rm -rf $TMPFILE2
  398.     else
  399.         echo "$ONLINE5"
  400.     fi
  401.     return 0
  402. }
  403.  
  404. #END_CM_SCRIPTLIB
  405.  
  406. # Check the installation status of the product with prd=$PRDVALUE
  407. preinst_check() {
  408.  
  409.     set -- `who -r`
  410.     case $3 in
  411.     S)    : Feeling groovy
  412.     ;;
  413.     *)  cat >&2 <<HERE
  414. This SLS should be installed in single user mode.  Please
  415. shut the system down before running custom
  416. HERE
  417.     return 1
  418.     ;;
  419.     esac
  420.  
  421.     return 0
  422. }
  423.  
  424. #MAIN
  425.  
  426. PRDVALUE=mmdfsls1
  427. export PRDVALUE
  428.  
  429. # get permlist information
  430. cd /
  431.  
  432. setvars
  433.  
  434. preinst_check || {
  435.     echo "There has been an error in the prep script."
  436.     echo "Aborting installation..."
  437.     exit 1
  438. }
  439.  
  440. # optional backup of all files that may potentially be overwritten
  441. echo " "
  442. allbackup $PRDVALUE || {
  443.     echo "Warning: Unable to backup complete file list"
  444.     getyn "Do you want to continue with Installation ?" || exit $FAIL
  445. }
  446.  
  447. respond "Press return to continue" || exit 1
  448.  
  449. exit 0
  450.